global !p

from mdtex.scopes import text
from md.text import *
from mdtex.variables import *

endglobal

################################################################
#                                                              #
#                            Common                            #
#                                                              #
################################################################

# 不再支持自动添加空格（由于 BUG 与不稳定性）
# No longer Support automatically add space (in case of BUG and instability)
context "text()"
snippet '(?a)(\W?)\blm' "行内公式 Inline Formula" Ar
`!p snip.rv = match.group(1) + ('' if match.group(1) in punctuations else ' ') + \
              delis_i[deli_i_option][0]`$1`!p snip.rv = delis_i[deli_i_option][1]` $0
endsnippet

context "text()"
snippet dm "行间公式 Display Formula" Ab
`!p snip.rv = delis_d[deli_d_option][0]`
${1:${VISUAL}}
`!p snip.rv = delis_d[deli_d_option][1]`
$0
endsnippet

context "text()"
pre_expand "create_table(snip)"
snippet "\btb([1-9]{2})" "普通表格 Table" br
endsnippet

context "text()"
pre_expand "create_table(snip, 1)"
snippet "\btbl([1-9]{2})" "靠左表格 Left Table" br
endsnippet

context "text()"
pre_expand "create_table(snip, 2)"
snippet "\btbr([1-9]{2})" "靠右表格 Right Table" br
endsnippet

context "text()"
pre_expand "create_table(snip, 3)"
snippet "\btbm([1-9]{2})" "居中表格 Center Table" br
endsnippet

context "text()"
snippet todo "待办 Todo" b
- [${1|x, |}] $0
endsnippet

snippet "- \[([ x])\] (.+)" "待办 Todo" br
`!p snip.rv = '- [' + (' ' if match.group(1) == 'x' else 'x') + '] ' + match.group(2)`
endsnippet

context "text()"
snippet lnk "链接 Link" w
[${1:${VISUAL}}](${2:https://${3:}})$0
endsnippet

context "text()"
snippet imgs "图像 Image" w
![$1](${2:/}images/${3:${VISUAL}})$0
endsnippet

context "text()"
snippet img "图像 Image" w
![$1](${2:${VISUAL}})$0
endsnippet

context "text()"
snippet "(?a)\b([a-zA-Z0-9_^+=%\.<>\[\]\(\)\-]+)(;;|；；)" "行间代码 Inline Code" Ar
\``!p snip.rv = match.group(1)`\` $0
endsnippet

context "text()"
snippet code "代码 Code Block" b
\`\`\`$1
${2:${VISUAL}}
\`\`\`
$0
endsnippet

context "text()"
snippet kbd "按键 Key" w
<kbd>${1:${VISUAL}}</kbd>$0
endsnippet

context "text()"
snippet fnt "脚注 FootNote" w
[^${1:${VISUAL}}]$0
endsnippet

context "text()"
snippet detail "详情 Disclosure" w
<!-- {{{ $1 -->
<details>
<summary>$1</summary>

${2:${VISUAL}}

</details>
<!-- }}} -->
$0
endsnippet

context "text()"
snippet ii "斜体 Italics" i
*${1:${VISUAL}}*$0
endsnippet

context "text()"
snippet bb "粗体 Bold" i
**${1:${VISUAL}}**$0
endsnippet

context "text()"
snippet bi "粗斜体 Bold Italics" i
***${1:${VISUAL}}***$0
endsnippet

context "text()"
snippet mm "高亮 Mark" i
==${1:${VISUAL}}==$0
endsnippet

context "text()"
snippet == "高亮 Mark" i
==${1:${VISUAL}}==$0
endsnippet

context "text()"
snippet ss "删除 Delete" i
~~${1:${VISUAL}}~~$0
endsnippet

context "text()"
snippet uu "下划线 Underline" i
<u>${1:${VISUAL}}</u>$0
endsnippet

context "text()"
snippet /. "注释 Comment" i
<!-- ${1:${VISUAL}} -->$0
endsnippet

context "text()"
snippet "^#([1-6])" "段落 Paragraph" Ar
`!p snip.rv = '#' * int(match.group(1))` 
endsnippet
